
<template>
  <el-form ref="dataForm" :rules="rules" >
    <el-form-item label-width="120px" label="重新填报决算金额原因"  required >
      <el-input width="100%"  type="textarea" v-model="formData.reFee" placeholder="重新填报决算金额原因"></el-input>
    </el-form-item>

   <el-radio-group v-model="valueRadio" >
      <el-radio
        label="TACHE00130001"
        key="TACHE00130001"
      >
      重新填报甲端决算金额
      </el-radio>
      <el-radio
        label="TACHE00130002"
        key="TACHE00130002"
      >
    重新填报乙端决算金额
      </el-radio>
      <el-radio
        label="TACHE00130001,TACHE00130002"
        key="TACHE00130001,TACHE00130002"
      >
     重新填报两端决算金额
      </el-radio>
    </el-radio-group>


    <el-form-item class="btnDir">
      <el-button @click="onSubmit">确 定</el-button>
      <el-button @click="onCancel">取 消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import requestUtil from '@/utils/requestEnc';
import CustOrderService from "@/api/order/CustOrderService";
import { mapState } from "vuex";
export default {
 components: {
		requestUtil,
		CustOrderService,
  },
  computed: {
		...mapState("orders", ["orderItemList"]),
		...mapState("user", ["user"]),
	},
  async mounted(){


     if(this.CTOInfo instanceof Array){
      this.newCTOInfo = this.CTOInfo;
    }else{
      this.newCTOInfo = [this.CTOInfo];
    }

    if(this.newCTOInfo.length > 0){
      var orderItemIds="";
      
      for(var i=0;i<this.newCTOInfo.length;i++){
         if(i==0){
           orderItemIds += this.newCTOInfo[i].orderItemId;
         }else{
            orderItemIds += ","+this.newCTOInfo[i].orderItemId;
         }
      }
      // var scopeInfos=[]
      // scopeInfos.push({scope:"orderTasks"});
      // var custSoNumber = this.newCTOInfo[0].custSoNumber;
      // var batchNbr =  this.newCTOInfo[0].batchNbr;
      // var custId = this.newCTOInfo[0].custId;
      
      this.orderItemIds = orderItemIds;
      // const result=await CustOrderService.qryCustomerOrderDetail({custSoNumber,batchNbr,orderItemIds,custId,scopeInfos});
      // var  orderTask = result.orderDetails[0]['orderTasks'][0];
      // this.orderTask = orderTask;

    }else{
      this.Form.TASK_NAME.value = "";
    }
  },
  watch:{

  },
  props:{
	  	ODKInfo: {
			type: Object,
			default: () => {
				return {};
			},
		},
		CTOInfo: {
			type: [Array,Object],
			default: () => {
				return [];
			},
		},
  },
  data() {
    return {
      newCTOInfo:[],
      formData:{
        reFee:"",
      },
      valueRadio:"",
      orderTask:{},
      orderItemIds:"",
      rules:{
        reFee:[
          { required: true, message: '重新填报决算金额原因不能为空', trigger: 'blur' },
        ]
      }
    }
  },
  methods: {
    onCancel(){
     this.$emit("close");
    },
    async onSubmit(){
     
        if(this.formData.reFee == '' || this.formData.reFee == null){
           this.$confirm("重新填报决算金额原因不能为空!", "提示", {
          confirmButtonText: "确定",
          showCancelButton: false,
          type: "warn",
          center: true,
        });
        return;
        }

        if(this.valueRadio == '' || this.valueRadio == null){
           this.$confirm("填报类型不能为空！", "提示", {
          confirmButtonText: "确定",
          showCancelButton: false,
          type: "warn",
          center: true,
        });
        return;
        }

          this.submit();
       
    },
   async submit(){

     

       var param = {
          statusCds: this.newCTOInfo[0].statusCd, //订单状态
          custSoNumber: this.newCTOInfo[0].custSoNumber, //流水号  从上个页面带回
          handleOrgId: this.user.staffId,
          custId: this.newCTOInfo[0].custId,
          batchNbr: this.newCTOInfo[0].batchNbr, //批次号
          accNum: "", //设备号,没有不传
          orderItemIds:this.orderItemIds,
          taskId:"TACHE00140001",  //重新结算金额完成 生成决算单任务  回退到上一步 
          taskIds:this.valueRadio,
          orderAuditId:this.newCTOInfo[0].orderAuditId,
          oneOrmany:"many",
          userId:this.user.staffId,
         "orderTasks":[{
            actType:"MOD",
            orderItemId:this.orderItemIds,
            taskId:this.valueRadio,
            taskComment:this.formData.reFee,
            custId:this.newCTOInfo[0].custId
         }]
       }

      var result = await CustOrderService.updateReFillBalance(param);
      
      if(result.meta && result.meta.meta == "0"){
							this.$confirm("成功", "提示", {
								confirmButtonText: "确定",
								showCancelButton: false,
								type: "success",
								center: true
                });
                this.$emit("close");
					}else{
						this.$confirm(result.meta, "提示", {
								confirmButtonText: "确定",
								showCancelButton: false,
								type: "warn",
								center: true
                });
              
					}
    }
  }
};
</script>

<style>
.el-form--inline .el-form-item {
  display: inline-flex;
  margin-right: 0.1rem;
  vertical-align: top;
  width: 42%;
}

.el-form-item__label {
  width: 94px;
}
.btnDir {
  margin-left: 36%;
  margin-top: 19px;
}
</style>
